/*
 * user.c
 *
 *  Created on: 2025年6月30日
 *      Author: Administrator
 */
#include "user.h"

//////////////////////////////////自定义变量///////////////////////////////////////////
////////////////////////////////////////MVB-CRC
uint8_t CRCBYTE137[30];
uint8_t CRCBYTE702[30];
uint8_t CRCBYTE706[30];
uint8_t CRCBYTE421[30];
uint8_t CRCBYTE021[30];
uint8_t CRCBYTE703[30];
uint8_t CRCBYTE707[30];

uint16_t M_MVB421[16];
uint16_t M_MVB021[16];
uint16_t M_MVB703[16];
uint16_t M_MVB707[16];

uint16_t CRC_MVB421;
uint16_t CRC_MVB021;
uint16_t CRC_MVB703;
uint16_t CRC_MVB707;
uint8_t CRC_MVB421_err;
uint8_t CRC_MVB021_err;
uint8_t CRC_MVB703_err;
uint8_t CRC_MVB707_err;
///////////////////////////////////////MVB
uint16_t MVB137[16];
uint16_t MVBRCU[16];
uint16_t MVB421[16];
uint16_t MVB021[16];

uint16_t MVB702[16];
uint16_t MVB706[16];
uint16_t MVBATO[16];
uint16_t MVB703[16];
uint16_t MVB707[16];
//////////////////////////////////////CAN
uint8_t CAN91[8];
uint8_t CAN92[8];

uint8_t EBV11[8];
uint8_t EIU31[8];
uint8_t EIU32[8];
uint8_t EIU33[8];
//uint8_t EIU34[8];
/**20230526_begin***********************************************************/
uint8_t EIU3A[8];
/**20230526_end***********************************************************/
uint8_t EIUA3[8];
uint8_t EIUA4[8];
uint8_t EIUA5[8];
uint8_t EIUA6[8];
uint8_t BPCM61[8];
uint8_t BPCM62[8];
uint8_t BPCM63[8];
uint8_t BCCM71[8];
uint8_t BCCM72[8];
uint8_t BCCM73[8];
uint8_t BCCM74[8];
uint8_t IBCM81[8];
uint8_t IBCM82[8];

uint8_t EBV11_A[8];
uint8_t EIU31_A[8];
uint8_t EIU32_A[8];
uint8_t EIU33_A[8];
//uint8_t EIU34_A[8];
/**20230526_begin***********************************************************/
uint8_t EIU3A_A[8];
/**20230526_end***********************************************************/
uint8_t EIUA3_A[8];
uint8_t EIUA4_A[8];
uint8_t EIUA5_A[8];
uint8_t EIUA6_A[8];
uint8_t BPCM61_A[8];
uint8_t BPCM62_A[8];
uint8_t BPCM63_A[8];
uint8_t BCCM71_A[8];
uint8_t BCCM72_A[8];
uint8_t BCCM73_A[8];
uint8_t BCCM74_A[8];
uint8_t IBCM81_A[8];
uint8_t IBCM82_A[8];

uint8_t EBV11_B[8];
uint8_t EIU31_B[8];
uint8_t EIU32_B[8];
uint8_t EIU33_B[8];
//uint8_t EIU34_B[8];
/**20230526_begin***********************************************************/
uint8_t EIU3A_B[8];
/**20230526_end***********************************************************/
uint8_t EIUA3_B[8];
uint8_t EIUA4_B[8];
uint8_t EIUA5_B[8];
uint8_t EIUA6_B[8];
uint8_t BPCM61_B[8];
uint8_t BPCM62_B[8];
uint8_t BPCM63_B[8];
uint8_t BCCM71_B[8];
uint8_t BCCM72_B[8];
uint8_t BCCM73_B[8];
uint8_t BCCM74_B[8];
uint8_t IBCM81_B[8];
uint8_t IBCM82_B[8];
////////////////////////////////////////双路冗余
uint8_t Can1_cnt;
uint8_t Can2_cnt;
//uint8_t Can_1or2;
uint8_t EBV_Can1_cnt;
uint8_t EBV_Can2_cnt;
uint8_t EIU_Can1_cnt;
uint8_t EIU_Can2_cnt;
uint8_t BPCM_Can1_cnt;
uint8_t BPCM_Can2_cnt;
uint8_t BCCM_Can1_cnt;
uint8_t BCCM_Can2_cnt;
uint8_t IBCM_Can1_cnt;
uint8_t IBCM_Can2_cnt;
/////////////////////////////////////////EBV
uint8_t autoBrkHand_EMG;
uint8_t autoBrkHand_MUL;
uint8_t autoBrkHand_RES;
uint8_t autoBrkHand_MAXBRK;
uint8_t autoBrkHand_BRK;
uint8_t autoBrkHand_MINBRK;
uint8_t autoBrkHand_RUN;
uint8_t indBrkHand_REL;
uint8_t indBrkHand_MAXBRK;
uint8_t indBrkHand_BRK;
uint8_t indBrkHand_Run;
uint8_t EBV_life_err;
uint8_t EBV_autoBrk_Fault;
uint8_t EBV_indBrk_Fault;
uint8_t BCU_indBrkTarget_valid;
uint16_t autoBrkAI_int;
uint16_t indBrkAI_int;
uint16_t BCU_indBrkTarget;
////////////////////////////////////////EBV-END
////////////////////////////////////////MVB
uint8_t RCU_lifesignal_fault;
uint8_t RCU_Comm_fault;
uint8_t ATO_lifesignal_fault;

uint8_t RCU_LocoSpeed;
uint8_t RCU_leakPress;
uint8_t RCU_leaktest_req3;
uint8_t RCU_254YV;
uint8_t RCU_indBrkHand_REL;
uint8_t RCU_Em_req;
uint8_t RCU_Penalty_req;

uint16_t original_RCU_ERPressTarget;
uint16_t RCU_ERPressTarget;
uint16_t RCU_indBrkTarget;
uint8_t RCU_autoBrkHand_EMG;
uint8_t RCU_autoBrkHand_RES;
uint8_t RCU_autoBrkHand_MINBRK;

uint8_t RCU_PenaltyPress;
uint8_t RCU_RDP_type;
uint8_t RCU_leaktest_state;
uint8_t RCU_LocoSpeedZero5km;
uint8_t RCU_DPmode;
uint8_t RCU_DPmode_valid;
uint8_t RCU_Loco_mode;
uint8_t RCU_LocotoLoco_commerr;

uint16_t ATO_ERPressTarget;
uint16_t ATO_BCPressTarget;
uint8_t ATO_active_req;
uint8_t ATO_exit_req;
uint8_t ATO_ATOstate;
uint8_t ATO_indBrkHand_REL;
uint16_t original_ATO_ERPressTarget;
/////////////////////////////////////////MVB-END
/////////////////////////////////////////EIU-EPCU
uint8_t BCU_Em;
uint8_t BCU_Penalty;
uint8_t BCU_mode;
uint16_t ERPress;
uint16_t BPPress;
uint16_t MRPress;
uint16_t BCPress;
uint16_t RateofFlow;
uint16_t BCU_ERPressTarget;
uint8_t  BPsetpoint;
uint16_t BPsetpoint_Press;

uint8_t EIU_life_err  = 1;
uint8_t BPCM_life_err = 1;
uint8_t BCCM_life_err = 1;
uint8_t IBCM_life_err = 1;

uint8_t BPCM_applyfor_BCCM;
uint8_t BCCM_replace_BPCM;
uint8_t	BCUfault_to_exitATO;

uint8_t RateofFlow_valid;
uint8_t ERPress_valid;
uint8_t MRPress_valid;
uint8_t BPPress_valid;
uint8_t BCU_ERPressTarget_valid;

uint8_t BPCM_applyfor_BCCM_Penalty;
uint8_t BCCM_BPCMlife_err_Penalty;

uint8_t BPCM_EM60s_countdown;
uint8_t BCCM_EM60s_countdown;
uint8_t EM60s_countdown;
//////////////////////////////////////EIU-EPCU-END
//////////////////////////////////////RCU
uint8_t BCUmode_to_RCU;
uint8_t BCU_253YV;
uint8_t BCU_254YV;
uint8_t BCU_PenaltyPress_state;
uint8_t BCU_leaktest_state;
uint8_t BCU_RDP_mode;

uint16_t BCU_indBrkTarget_to_RCUorATO;
uint8_t indBrkHand_REL_state;
uint8_t CAN91RCU_Em_req;
//////////////////////////////////////RCU-END
//////////////////////////////////////ATO
uint8_t EIULocoSpeedZero;
uint8_t BCUmode_to_ATO;
uint8_t BCU_ATO_state;
uint8_t IIU_ATO_state;
uint16_t CAN92_ERPressTarget;
uint16_t CAN92_indBrkTarget;
/////////////////////////////////////ATO-END
uint8_t IIU_lifesignal;
uint8_t BrakeSystype_toRCU;
uint8_t BrakeSysID_toATO;
/////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////

unsigned short c_Crc16Table_aU16[256]=
{
    0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
    0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
    0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
    0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
    0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
    0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
    0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
    0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
    0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
    0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
    0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
    0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
    0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
    0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
    0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
    0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
    0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
    0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
    0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
    0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
    0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
    0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
    0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
    0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
    0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
    0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
    0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
    0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
    0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
    0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
    0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
    0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
};
uint16_t Comn_F_GetCRC16(uint16_t inTable_aU16[256],uint16_t inCRCInit_U16,uint8_t inBuf_aU8[],uint8_t inLEN_I32)
{
	uint16_t i = 0;
	uint16_t vCRC16_U16 = inCRCInit_U16;
	uint8_t  vTemp_U8 = 0;

    while(i < inLEN_I32)
    {
        vTemp_U8   = (uint8_t)(((vCRC16_U16 >> 8) ^ inBuf_aU8[i]) & 0xFF);
        vCRC16_U16 = (uint16_t)(vCRC16_U16 << 8) ^ inTable_aU16[vTemp_U8];
        i ++;
    }
    return vCRC16_U16;
}


uint16_t min(uint16_t a,uint16_t b)
{
	uint16_t c;
	if(a <= b)
	{
		c = a;
	}
	else
	{
		c = b;
	}

	return c;
}

uint8_t EBVPos_filter(uint8_t num,uint8_t RecEBVPos,uint8_t Cyc)//15
{
	static uint8_t EBV_Position[15] = {0};
	static uint8_t count0to1_ub[15] = {0};
	static uint8_t count1to0_ub[15] = {0};
	if(RecEBVPos)//
	{
		count1to0_ub[num] = 0;
		if(count0to1_ub[num] < Cyc)
		{
			count0to1_ub[num] = count0to1_ub[num] + 1;
		}
		else
		{
			count0to1_ub[num]   = Cyc;
			EBV_Position[num] = 1;
		}
	}
	else//
	{
		count0to1_ub[num] = 0;
		if(count1to0_ub[num] < Cyc)
		{
			count1to0_ub[num] = count1to0_ub[num] + 1;
		}
		else
		{
			count1to0_ub[num]   = Cyc;
			EBV_Position[num] = 0;
		}
	}
	return EBV_Position[num];
}

uint8_t EIU_EPCU_filter(uint8_t num,uint8_t RecEIU_CAN,uint8_t high,uint8_t low)//40
{
	static uint8_t EIU_CAN[40]      = {0};
	static uint8_t count0to1_ub[40] = {0};
	static uint8_t count1to0_ub[40] = {0};
	if(RecEIU_CAN)//
	{
		count1to0_ub[num] = 0;
		if(count0to1_ub[num] < high)
		{
			count0to1_ub[num] = count0to1_ub[num] + 1;
		}
		else
		{
			count0to1_ub[num] = high;
			EIU_CAN[num]     = 1;
		}
	}
	else//
	{
		count0to1_ub[num] = 0;
		if(count1to0_ub[num] < low)
		{
			count1to0_ub[num] = count1to0_ub[num] + 1;
		}
		else
		{
			count1to0_ub[num] = low;
			EIU_CAN[num]     = 0;
		}
	}
	return EIU_CAN[num];
}

uint8_t MVB_filter(uint8_t num,uint8_t RecMVB,uint8_t high,uint8_t low)//20
{
	static uint8_t MVB_data[20] = {0};
	static uint8_t count0to1_ub[20] = {0};
	static uint8_t count1to0_ub[20] = {0};
	if(RecMVB)//
	{
		count1to0_ub[num] = 0;
		if(count0to1_ub[num] < high)
		{
			count0to1_ub[num] = count0to1_ub[num] + 1;
		}
		else
		{
			count0to1_ub[num] = high;
			MVB_data[num]     = 1;
		}
	}
	else//
	{
		count0to1_ub[num] = 0;
		if(count1to0_ub[num] < low)
		{
			count1to0_ub[num] = count1to0_ub[num] + 1;
		}
		else
		{
			count1to0_ub[num] = low;
			MVB_data[num]     = 0;
		}
	}
	return MVB_data[num];
}

uint8_t lifesignal_detect(uint8_t num,uint8_t Rec_lifesignal_u8,uint8_t Cyc)//15
{
	static uint8_t count_life_u8[15]      = {0};
	static uint8_t Last_lifesignal_u8[15] = {0};
	static uint8_t life_err[15] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};

	if(Rec_lifesignal_u8 == Last_lifesignal_u8[num])
	{
		if(count_life_u8[num] < Cyc)
		{
			count_life_u8[num] = count_life_u8[num] + 1;
		}
		else
		{
			count_life_u8[num] = Cyc;
			life_err[num] = 1;
		}
	}
	else
	{
		count_life_u8[num] = 0;
		life_err[num]    = 0;
	}
	Last_lifesignal_u8[num] = Rec_lifesignal_u8;

	return life_err[num];
}

void Choose_CANAorB_Data()
{
	uint8_t i=0;
////////////////////////////////////////////////
	if(EBV_Can1_cnt <= 5)
	{
	  for (i = 0; i < 8; i++)
	  {
		  EBV11[i] = EBV11_A[i];
	  }
	}
	else if(EBV_Can2_cnt <= 5)
	{
	  for (i = 0; i < 8; i++)
	  {
		  EBV11[i] = EBV11_B[i];
	  }
	}
////////////////////////////////////////////////
	if(EIU_Can1_cnt <= 5)
	{
	  for (i = 0; i < 8; i++)
	  {
		  EIU31[i] = EIU31_A[i];
		  EIU32[i] = EIU32_A[i];
		  EIU33[i] = EIU33_A[i];

		  EIUA3[i] = EIUA3_A[i];
		  EIUA4[i] = EIUA4_A[i];
		  EIUA5[i] = EIUA5_A[i];
		  EIUA6[i] = EIUA6_A[i];

		  EIU3A[i] = EIU3A_A[i];
	  }
	}
	else if(EIU_Can2_cnt <= 5)
	{
	  for (i = 0; i < 8; i++)
	  {
		  EIU31[i] = EIU31_B[i];
		  EIU32[i] = EIU32_B[i];
		  EIU33[i] = EIU33_B[i];

		  EIUA3[i] = EIUA3_B[i];
		  EIUA4[i] = EIUA4_B[i];
		  EIUA5[i] = EIUA5_B[i];
		  EIUA6[i] = EIUA6_B[i];

		  EIU3A[i] = EIU3A_B[i];
	  }
	}
////////////////////////////////////////////////
	if(BPCM_Can1_cnt <= 5)
	{
	  for (i = 0; i < 8; i++)
	  {
		  BPCM61[i] = BPCM61_A[i];
		  BPCM62[i] = BPCM62_A[i];
		  BPCM63[i] = BPCM63_A[i];
	  }
	}
	else if(BPCM_Can2_cnt <= 5)
	{
      for (i = 0; i < 8; i++)
	  {
		  BPCM61[i] = BPCM61_B[i];
		  BPCM62[i] = BPCM62_B[i];
		  BPCM63[i] = BPCM63_B[i];
	  }
	}

	if(BCCM_Can1_cnt <= 5)
	{
	  for (i = 0; i < 8; i++)
	  {
		  BCCM71[i] = BCCM71_A[i];
		  BCCM72[i] = BCCM72_A[i];
		  BCCM73[i] = BCCM73_A[i];
		  BCCM74[i] = BCCM74_A[i];
	  }
	}
	else if(BCCM_Can2_cnt <= 5)
	{
	  for (i = 0; i < 8; i++)
	  {
		  BCCM71[i] = BCCM71_B[i];
		  BCCM72[i] = BCCM72_B[i];
		  BCCM73[i] = BCCM73_B[i];
		  BCCM74[i] = BCCM74_B[i];
	  }
	}

	if(IBCM_Can1_cnt <= 5)
	{
	  for (i = 0; i < 8; i++)
	  {
		  IBCM81[i] = IBCM81_A[i];
		  IBCM82[i] = IBCM82_A[i];
	  }
	}
	else if(IBCM_Can2_cnt <= 5)
	{
	  for (i = 0; i < 8; i++)
	  {
		  IBCM81[i] = IBCM81_B[i];
		  IBCM82[i] = IBCM82_B[i];
	  }
	}
}

void Receive_EBV()
{
	static uint16_t cnt_indBrkHand_RELcode;
	uint8_t M_autoBrkHand_RUN    ; //
	uint8_t M_autoBrkHand_MINBRK ; //
	uint8_t M_autoBrkHand_BRK	 ; //
	uint8_t M_autoBrkHand_MAXBRK ; //
	uint8_t M_autoBrkHand_RES    ; //
	uint8_t M_autoBrkHand_MUL    ; //
	uint8_t M_autoBrkHand_EMG    ; //

	uint8_t MM_autoBrkHand_RUN    ;
	uint8_t MM_autoBrkHand_MINBRK ; //
	uint8_t MM_autoBrkHand_BRK	  ; //
	uint8_t MM_autoBrkHand_MAXBRK ; //
	uint8_t MM_autoBrkHand_RES    ; //
	uint8_t MM_autoBrkHand_MUL    ; //
	uint8_t MM_autoBrkHand_EMG    ; //

	uint8_t M_indBrkHand_Run     ; //
	uint8_t M_indBrkHand_BRK     ; //
	uint8_t M_indBrkHand_MAXBRK  ; //
	uint8_t M_indBrkHand_REL     ; //
	uint8_t M_indBrkHand_RELcode ;

	uint8_t MM_indBrkHand_Run     ; //
	uint8_t MM_indBrkHand_BRK     ; //
	uint8_t MM_indBrkHand_MAXBRK  ; //
	uint8_t MM_indBrkHand_REL     ; //

	uint8_t M_EBV_autoBrk_Fault  ;//
	uint8_t M_EBV_indBrk_Fault   ;//
	uint8_t EBVlifeSignal  = 0;
//////////////////////////////////////////////////////////////////
	EBVlifeSignal = EBV11[7];
	EBV_life_err  = lifesignal_detect(0,EBVlifeSignal,60);

	autoBrkAI_int = EBV11[3] + ((EBV11[4]&0x0f)<<8);  //
	indBrkAI_int  = ((EBV11[4]&0xf0)<<4) + EBV11[5];  //

	MM_autoBrkHand_RUN    = EBV11[2]&0x01; //
	MM_autoBrkHand_MINBRK = EBV11[2]&0x02; //
	MM_autoBrkHand_BRK	  = EBV11[1]&0x40; //
	MM_autoBrkHand_MAXBRK = EBV11[2]&0x04; //
	MM_autoBrkHand_RES    = EBV11[2]&0x08; //
	MM_autoBrkHand_MUL    = EBV11[2]&0x10; //
	MM_autoBrkHand_EMG    = EBV11[2]&0x20; //

	MM_indBrkHand_Run     = EBV11[1]&0x01; //
	MM_indBrkHand_BRK     = EBV11[1]&0x80; //
	MM_indBrkHand_MAXBRK  = EBV11[1]&0x02; //
	MM_indBrkHand_REL     = EBV11[1]&0x04; //

	M_EBV_autoBrk_Fault    = EBV11[6]&0x01;
	M_EBV_indBrk_Fault     = EBV11[6]&0x02;

	M_autoBrkHand_RUN    = EBVPos_filter(0,MM_autoBrkHand_RUN,3);   //
	M_autoBrkHand_MINBRK = EBVPos_filter(1,MM_autoBrkHand_MINBRK,3);//
	M_autoBrkHand_BRK    = EBVPos_filter(2,MM_autoBrkHand_BRK,3);  //
	M_autoBrkHand_MAXBRK = EBVPos_filter(3,MM_autoBrkHand_MAXBRK,3);//
	M_autoBrkHand_RES    = EBVPos_filter(4,MM_autoBrkHand_RES,3);   //
	M_autoBrkHand_MUL    = EBVPos_filter(5,MM_autoBrkHand_MUL,3);   //
	M_autoBrkHand_EMG    = EBVPos_filter(6,MM_autoBrkHand_EMG,3);   //

	M_indBrkHand_Run     = EBVPos_filter(7,MM_indBrkHand_Run,3);    //
	M_indBrkHand_BRK     = EBVPos_filter(8,MM_indBrkHand_BRK,3);    //
	M_indBrkHand_MAXBRK  = EBVPos_filter(9,MM_indBrkHand_MAXBRK,3);//
	M_indBrkHand_RELcode = EBVPos_filter(10,MM_indBrkHand_REL,3);   //

	EBV_autoBrk_Fault     = EBVPos_filter(11,M_EBV_autoBrk_Fault,3);
	EBV_indBrk_Fault      = EBVPos_filter(12,M_EBV_indBrk_Fault,3);

	if(M_indBrkHand_RELcode)
	{
		if(cnt_indBrkHand_RELcode < 3600)//180s
		{
			cnt_indBrkHand_RELcode = cnt_indBrkHand_RELcode + 1;
			M_indBrkHand_REL = 1;
		}
		else
		{
			M_indBrkHand_REL = 0;
		}
	}
	else
	{
		cnt_indBrkHand_RELcode = 0;
		M_indBrkHand_REL = 0;
	}

	if(M_autoBrkHand_EMG)
	{
		autoBrkHand_EMG = 1;
		autoBrkHand_MUL = 0;
		autoBrkHand_RES = 0;
		autoBrkHand_MAXBRK = 0;
		autoBrkHand_BRK = 0;
		autoBrkHand_MINBRK = 0;
		autoBrkHand_RUN = 0;
	}
	else if(M_autoBrkHand_MUL)
	{
		autoBrkHand_EMG = 0;
		autoBrkHand_MUL = 1;
		autoBrkHand_RES = 0;
		autoBrkHand_MAXBRK = 0;
		autoBrkHand_BRK = 0;
		autoBrkHand_MINBRK = 0;
		autoBrkHand_RUN = 0;
	}
	else if(M_autoBrkHand_RES)
	{
		autoBrkHand_EMG = 0;
		autoBrkHand_MUL = 0;
		autoBrkHand_RES = 1;
		autoBrkHand_MAXBRK = 0;
		autoBrkHand_BRK = 0;
		autoBrkHand_MINBRK = 0;
		autoBrkHand_RUN = 0;
	}
	else if(M_autoBrkHand_MAXBRK)
	{
		autoBrkHand_EMG = 0;
		autoBrkHand_MUL = 0;
		autoBrkHand_RES = 0;
		autoBrkHand_MAXBRK = 1;
		autoBrkHand_BRK = 0;
		autoBrkHand_MINBRK = 0;
		autoBrkHand_RUN = 0;
	}
	else if(M_autoBrkHand_BRK)
	{
		autoBrkHand_EMG = 0;
		autoBrkHand_MUL = 0;
		autoBrkHand_RES = 0;
		autoBrkHand_MAXBRK = 0;
		autoBrkHand_BRK = 1;
		autoBrkHand_MINBRK = 0;
		autoBrkHand_RUN = 0;
	}
	else if(M_autoBrkHand_MINBRK)
	{
		autoBrkHand_EMG = 0;
		autoBrkHand_MUL = 0;
		autoBrkHand_RES = 0;
		autoBrkHand_MAXBRK = 0;
		autoBrkHand_BRK = 0;
		autoBrkHand_MINBRK = 1;
		autoBrkHand_RUN = 0;
	}
	else if(M_autoBrkHand_RUN)
	{
		autoBrkHand_EMG = 0;
		autoBrkHand_MUL = 0;
		autoBrkHand_RES = 0;
		autoBrkHand_MAXBRK = 0;
		autoBrkHand_BRK = 0;
		autoBrkHand_MINBRK = 0;
		autoBrkHand_RUN = 1;
	}
//////////////////////////////////////////////////
	if(M_indBrkHand_REL)
	{
		indBrkHand_REL = 1;
		indBrkHand_MAXBRK = 0;
		indBrkHand_BRK = 0;
		indBrkHand_Run = 0;
	}
	else if(M_indBrkHand_MAXBRK)
	{
		indBrkHand_REL = 0;
		indBrkHand_MAXBRK = 1;
		indBrkHand_BRK = 0;
		indBrkHand_Run = 0;
	}
	else if(M_indBrkHand_BRK)
	{
		indBrkHand_REL = 0;
		indBrkHand_MAXBRK = 0;
		indBrkHand_BRK = 1;
		indBrkHand_Run = 0;
	}
	else if(M_indBrkHand_Run)
	{
		indBrkHand_REL = 0;
		indBrkHand_MAXBRK = 0;
		indBrkHand_BRK = 0;
		indBrkHand_Run = 1;
	}

	BCU_indBrkTarget = indBrkAI_int;

	/*
	if((!EBV_indBrk_Fault) && (indBrkAI_int>=0) && (indBrkAI_int<=300))
		BCU_indBrkTarget_valid = 1;
	else
		BCU_indBrkTarget_valid = 0;
	*/
}

void Receive_MVB()
{/////MVB发送要取反，MVB接收不用取反
	uint8_t i=0;
//////////////////////////////////////////
	uint8_t RCU421_lifesignal;
	uint8_t RCU021_lifesignal;
	uint8_t ATO703_lifesignal;
	uint8_t ATO707_lifesignal;
	uint8_t RCU421_lifesignal_fault;
	uint8_t RCU021_lifesignal_fault;
	uint8_t ATO703_lifesignal_fault;
	uint8_t ATO707_lifesignal_fault;
/////////////////20230801优化///////////////////////////
	uint8_t RCU421_comm_fault;
	uint8_t RCU021_comm_fault;
	uint8_t ATO703_comm_fault;
	uint8_t ATO707_comm_fault;
//////////////////////////////////////////////////////
	uint8_t RCU_leaktest_req6;
	uint8_t RCU_leak_result;

	uint8_t M_RCU_leaktest_req6;
	uint8_t M_RCU_254YV;
	uint8_t M_RCU_leaktest_req3;
	uint8_t M_RCU_indBrkHand_REL;
	uint8_t M_RCU_Em_req;
	uint8_t M_RCU_Penalty_req;

	uint8_t M_RCU_autoBrkHand_EMG;
	uint8_t M_RCU_autoBrkHand_RES;
	uint8_t M_RCU_autoBrkHand_MINBRK;

	uint8_t M_RCU_LocoSpeedZero5km;
	uint8_t M_RCU_DPmode;
	uint8_t M_RCU_DPmode_valid;
	uint8_t M_RCU_LocotoLoco_commerr;

	uint8_t M_ATO_active_req;
	uint8_t M_ATO_exit_req;
	uint8_t M_ATO_ATOstate;
	uint8_t M_ATO_indBrkHand_REL;

	RCU421_lifesignal = (MVB421[0]&0x00ff);
	RCU021_lifesignal = (MVB021[0]&0x00ff);
	ATO703_lifesignal  = (MVB703[3]&0x00ff);
	ATO707_lifesignal  = (MVB707[3]&0x00ff);
	/////MVB发送要取反，MVB接收不用取反
	RCU421_lifesignal_fault = lifesignal_detect(1,RCU421_lifesignal,80);
	RCU021_lifesignal_fault = lifesignal_detect(2,RCU021_lifesignal,80);
	RCU_lifesignal_fault    = RCU421_lifesignal_fault && RCU021_lifesignal_fault;

	ATO703_lifesignal_fault = lifesignal_detect(3,ATO703_lifesignal,80);
	ATO707_lifesignal_fault = lifesignal_detect(4,ATO707_lifesignal,80);
	ATO_lifesignal_fault    = ATO703_lifesignal_fault && ATO707_lifesignal_fault;
/////////////////2023080youhua///////////////////////////////
	RCU421_comm_fault = lifesignal_detect(10,RCU421_lifesignal,12);
	RCU021_comm_fault = lifesignal_detect(11,RCU021_lifesignal,12);
	ATO703_comm_fault = lifesignal_detect(12,ATO703_lifesignal,12);
	ATO707_comm_fault = lifesignal_detect(13,ATO707_lifesignal,12);

	if(!RCU421_comm_fault)
	{
		for(i=0;i<16;i++)
		    MVBRCU[i] = MVB421[i];
	}
	else if(!RCU021_comm_fault)
	{
		for(i=0;i<16;i++)
		    MVBRCU[i] = MVB021[i];
	}

	if(!ATO703_comm_fault)
	{
		for(i=0;i<16;i++)
			MVBATO[i] = MVB703[i];
	}
	else if(!ATO707_comm_fault)
	{
		for(i=0;i<16;i++)
			MVBATO[i] = MVB707[i];
	}
//////////////////////////////////////////////////////////////////////////////////
	/*
	if(!RCU421_lifesignal_fault)
	{
		for(i=0;i<16;i++)
		    MVBRCU[i] = MVB421[i];
	}
	else if(!RCU021_lifesignal_fault)
	{
		for(i=0;i<16;i++)
		    MVBRCU[i] = MVB021[i];
	}

	if(!ATO703_lifesignal_fault)
	{
		for(i=0;i<16;i++)
			MVBATO[i] = MVB703[i];
	}
	else if(!ATO707_lifesignal_fault)
	{
		for(i=0;i<16;i++)
			MVBATO[i] = MVB707[i];
	}
	*/
///////////////////////////////////////////////////////////////////////////////////RCU
	RCU_LocoSpeed     = (MVBRCU[2]&0x00ff);
	//original_RCU_ERPressTarget = MVBRCU[3];
	original_RCU_ERPressTarget =((MVBRCU[3]&0xff00)>>8)|((MVBRCU[3]&0x00ff)<<8);
	RCU_indBrkTarget  = MVBRCU[4];
	RCU_PenaltyPress  = (MVBRCU[7]&0xc000)>>14;
	RCU_RDP_type      = (MVBRCU[7]&0x3000)>>12;
	RCU_leak_result    = (MVBRCU[7]&0x0300)>>8;
	RCU_Loco_mode     = (MVBRCU[14]&0x0003);

	if(original_RCU_ERPressTarget >= BPsetpoint_Press)
		RCU_ERPressTarget = BPsetpoint_Press+2;
	else
		RCU_ERPressTarget = original_RCU_ERPressTarget;

	M_RCU_leaktest_req6      = (MVBRCU[2]&0x4000)>>14;
	M_RCU_254YV              = (MVBRCU[2]&0x1000)>>8;
	M_RCU_leaktest_req3      = (MVBRCU[2]&0x0800)>>8;
	M_RCU_indBrkHand_REL     = (MVBRCU[2]&0x0400)>>8;
	M_RCU_Em_req             = (MVBRCU[2]&0x0200)>>8;
	M_RCU_Penalty_req        = (MVBRCU[2]&0x0100)>>8;
	M_RCU_autoBrkHand_EMG    = (MVBRCU[7]&0x0080);
	M_RCU_autoBrkHand_RES    = (MVBRCU[7]&0x0040);
	M_RCU_autoBrkHand_MINBRK = (MVBRCU[7]&0x0020);

	M_RCU_LocoSpeedZero5km   = (MVBRCU[14]&0x0040);
	M_RCU_DPmode             = (MVBRCU[14]&0x0010);
	M_RCU_DPmode_valid       = (MVBRCU[14]&0x0008);
	M_RCU_LocotoLoco_commerr = (MVBRCU[8]&0x0001);

	RCU_leaktest_req6        = MVB_filter(0,M_RCU_leaktest_req6,6,6);
	RCU_254YV                = MVB_filter(1,M_RCU_254YV,6,6);
	RCU_leaktest_req3        = MVB_filter(2,M_RCU_leaktest_req3,6,6);

	//if(BCU_RDP_mode && (RCU_Loco_mode == 0x02))//zhukong
	  //RCU_254YV = RCU_254YV && (!RCU_lifesignal_fault);//20230621
	//RCU_leaktest_req3 = RCU_leaktest_req3 && (!RCU_lifesignal_fault);//20230621

	if(BCU_RDP_mode && (RCU_Loco_mode == 0x02))//zhukong,20230626
	{
		if(RCU_lifesignal_fault && autoBrkHand_MAXBRK)
		{
			RCU_254YV = 0;
			RCU_leaktest_req3 = 0;
		}
	}

	if(RCU_leaktest_req6 && RCU_leaktest_req3)
		RCU_leakPress = 0x03;//jianya170
	else if((!RCU_leaktest_req6) && RCU_leaktest_req3)
		RCU_leakPress = 0x02;//jianya100
	else
		RCU_leakPress = 0;

	RCU_indBrkHand_REL     = MVB_filter(3,M_RCU_indBrkHand_REL,6,6);
	RCU_Em_req             = MVB_filter(4,M_RCU_Em_req,6,6);
	RCU_Penalty_req        = MVB_filter(5,M_RCU_Penalty_req,6,6);

	RCU_autoBrkHand_EMG    = MVB_filter(6,M_RCU_autoBrkHand_EMG,6,6);
	RCU_autoBrkHand_RES    = MVB_filter(7,M_RCU_autoBrkHand_RES,6,6);
	RCU_autoBrkHand_MINBRK = MVB_filter(8,M_RCU_autoBrkHand_MINBRK,6,6);

	RCU_LocoSpeedZero5km   = MVB_filter(9,M_RCU_LocoSpeedZero5km,6,6);
	RCU_DPmode             = MVB_filter(10,M_RCU_DPmode,6,6);
	RCU_DPmode_valid       = MVB_filter(11,M_RCU_DPmode_valid,6,6);

	RCU_LocotoLoco_commerr= MVB_filter(16,M_RCU_LocotoLoco_commerr,6,6);//xinzneg16hao
	RCU_Comm_fault = RCU_lifesignal_fault || RCU_LocotoLoco_commerr;

	if(RCU_Comm_fault)
	{
		RCU_indBrkHand_REL = 0;
	}
//////////////////////////////////////////////////////////////////////////////////////RCU-END
/////////////////////////////////////////////////////////////////////////////////////ATO
	original_ATO_ERPressTarget    = ((MVBATO[4]&0x00ff)<<8)+((MVBATO[4]&0xff00)>>8);
	ATO_BCPressTarget    = ((MVBATO[5]&0x00ff)<<8)+((MVBATO[5]&0xff00)>>8);

	M_ATO_active_req     = (MVBATO[6]&0x0001);
	M_ATO_exit_req       = (MVBATO[6]&0x0002);
	M_ATO_ATOstate       = (MVBATO[6]&0x0004);
	M_ATO_indBrkHand_REL = (MVBATO[6]&0x0100)>>8;

	ATO_active_req    = MVB_filter(12,M_ATO_active_req,6,6);
	ATO_exit_req      = MVB_filter(13,M_ATO_exit_req,6,6);
	ATO_ATOstate      = MVB_filter(14,M_ATO_ATOstate,6,6);
	ATO_indBrkHand_REL= MVB_filter(15,M_ATO_indBrkHand_REL,6,6);

////////////////////////////////////////////////////////////////////////////20230522
	if(original_ATO_ERPressTarget < BPsetpoint_Press)
	{
		if(original_ATO_ERPressTarget < (BPsetpoint_Press-20))
		{
			if(original_ATO_ERPressTarget > (BPsetpoint_Press-55))
				ATO_ERPressTarget = BPsetpoint_Press - 55;
			else
				ATO_ERPressTarget = original_ATO_ERPressTarget;
		}
	}
	else
		ATO_ERPressTarget = BPsetpoint_Press+2;
///////////////////////////////////////////////////////////////////////////end

///////////////////////////////////////////////////////////////////////////////////ATO-END
}

void Receive_EIU_EPCU()
{
	uint8_t M_BCU_Em;
	uint8_t	M_BCU_Penalty;
//////////////////////////////////////////BPCM
	uint8_t BPCMsetpoint;
	uint16_t BPCMsetpointpress;
	uint8_t fault_203BP;
	uint8_t fault_200BP;
	uint8_t fault_204BP;
	uint8_t fault_205BP;
	uint8_t fault_258YV;
	uint8_t fault_257YV;
	uint8_t fault_267YV;
	uint8_t fault_253YV;
	uint8_t fault_254YV;
	uint8_t fault_96_1YV;
	uint8_t fault_96_2YV;

	uint8_t M_BPCMsetpoint;
	//uint16_t M_BPCMsetpointpress;
	uint8_t M_fault_203BP;
	uint8_t M_fault_200BP;
	uint8_t M_fault_204BP;
	uint8_t M_fault_205BP;
	uint8_t M_fault_258YV;
	uint8_t M_fault_257YV;
	uint8_t M_fault_267YV;
	uint8_t M_fault_253YV;
	uint8_t M_fault_254YV;
	uint8_t M_fault_96_1YV;
	uint8_t M_fault_96_2YV;
	uint8_t M_BPCM_applyfor_BCCM;

	uint8_t M_BPCM_applyfor_BCCM_Penalty;
///////////////////////////////////////////BPCM-END
///////////////////////////////////////////BCCM
	uint8_t BCCMsetpoint;
	uint16_t BCCMsetpointpress;
	uint8_t fault_201BP;
	uint8_t fault_212BP;
	uint8_t fault_206BP;
	uint8_t fault_269YV;
	uint8_t fault_276YV;
	uint8_t fault_264YV;
	uint8_t fault_198YV;
	uint8_t fault_260YV;
	uint8_t fault_261YV;
	uint8_t fault_207BP;

	uint8_t M_BCCMsetpoint;
	//uint16_t M_BCCMsetpointpress;
	uint8_t M_fault_201BP;
	uint8_t M_fault_212BP;
	uint8_t M_fault_206BP;
	uint8_t M_fault_269YV;
	uint8_t M_fault_276YV;
	uint8_t M_fault_264YV;
	uint8_t M_fault_198YV;
	uint8_t M_fault_260YV;
	uint8_t M_fault_261YV;
	uint8_t M_fault_207BP;
	uint8_t M_BCCM_replace_BPCM;

	uint8_t M_BCCM_BPCMlife_err_Penalty;
///////////////////////////////////////////BCCM-END
///////////////////////////////////////////IBCM
	uint8_t fault_208BP;
	uint8_t fault_213BP;
	uint8_t fault_209BP;
	uint8_t fault_210BP;
	uint8_t fault_265YV;
	uint8_t fault_266YV;
	uint8_t fault_272YV;
	uint8_t fault_196YV;

	uint8_t M_fault_208BP;
	uint8_t M_fault_213BP;
	uint8_t M_fault_209BP;
	uint8_t M_fault_210BP;
	uint8_t M_fault_265YV;
	uint8_t M_fault_266YV;
	uint8_t M_fault_272YV;
	uint8_t M_fault_196YV;
////////////////////////////////////////IBCM-END
	uint8_t BPCMfault_to_exitATO;
	uint8_t BCCMfault_to_exitATO;
	uint8_t IBCMfault_to_exitATO;
////////////////////////////////////////lifesignal
	uint8_t EIUlifeSignal1;
	uint8_t EIUlifeSignal2;
	uint8_t BPCMlifeSignal;
	uint8_t BCCMlifeSignal;
	uint8_t IBCMlifeSignal;

	uint8_t EIU_life_err1  = 1;
	uint8_t EIU_life_err2  = 1;

	EIUlifeSignal1 = EIU32[6];
	EIUlifeSignal2 = EIUA3[5];
	BPCMlifeSignal = BPCM62[7];
	BCCMlifeSignal = BCCM72[7];
	IBCMlifeSignal = IBCM82[6];

	EIU_life_err1 = lifesignal_detect(5,EIUlifeSignal1,60);
	EIU_life_err2 = lifesignal_detect(6,EIUlifeSignal2,60);
	EIU_life_err  = EIU_life_err1 && EIU_life_err2;
	BPCM_life_err = lifesignal_detect(7,BPCMlifeSignal,60);
	BCCM_life_err = lifesignal_detect(8,BCCMlifeSignal,60);
	IBCM_life_err = lifesignal_detect(9,IBCMlifeSignal,60);
//////////////////////////////////////////////////////////////////lifesignal-END
/////////////////////////////////////////////////////////////////
	if((!BPCM_life_err) && (!BCCM_life_err))
	{
		BCU_mode      = BPCM62[0]&0x03;
		M_BCU_Em      = (BPCM62[3]&0x20)||(BCCM73[4]&0x04);
		M_BCU_Penalty = (BPCM63[5]&0x01)||(BCCM73[4]&0x02);
	}
	else if(!BPCM_life_err)
	{
		BCU_mode      = BPCM62[0]&0x03;
		M_BCU_Em      = BPCM62[3]&0x20;
		M_BCU_Penalty = BPCM63[5]&0x01;
	}
	else if(!BCCM_life_err)
	{
		BCU_mode      = BCCM72[0]&0x03;
		M_BCU_Em      = BCCM73[4]&0x04;
		M_BCU_Penalty = BCCM73[4]&0x02;
	}

	M_BPCM_applyfor_BCCM = BPCM62[4]&0x80;
	M_BCCM_replace_BPCM  = BCCM72[3]&0x80;
	M_BPCMsetpoint       = BPCM62[0]&0x08;
	M_BCCMsetpoint       = BCCM72[0]&0x08;

	BCU_Em             = EIU_EPCU_filter(0,M_BCU_Em, 3, 3);
	BCU_Penalty        = EIU_EPCU_filter(1,M_BCU_Penalty, 3, 3);
	BPCM_applyfor_BCCM = EIU_EPCU_filter(2,M_BPCM_applyfor_BCCM, 3, 3);
	BCCM_replace_BPCM  = EIU_EPCU_filter(3,M_BCCM_replace_BPCM, 3, 3);
	BPCMsetpoint       = EIU_EPCU_filter(4,M_BPCMsetpoint, 3, 3);
	BCCMsetpoint       = EIU_EPCU_filter(5,M_BCCMsetpoint, 3, 3);
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////BPCM
	M_fault_203BP  = BPCM62[1]&0x20;
	M_fault_200BP  = BPCM62[1]&0x40;
	M_fault_204BP  = BPCM62[1]&0x80;
	M_fault_205BP  = BPCM62[2]&0x01;
	M_fault_258YV  = BPCM62[2]&0x02;
	M_fault_257YV  = BPCM62[2]&0x04;
	M_fault_267YV  = BPCM62[2]&0x08;
	M_fault_253YV  = BPCM62[2]&0x10;
	M_fault_254YV  = BPCM62[2]&0x20;
	M_fault_96_1YV = BPCM62[2]&0x40;
	M_fault_96_2YV = BPCM62[2]&0x80;

	fault_203BP  = EIU_EPCU_filter(6,M_fault_203BP, 3, 3);
	fault_200BP  = EIU_EPCU_filter(7,M_fault_200BP, 3, 3);
	fault_204BP  = EIU_EPCU_filter(8,M_fault_204BP, 3, 3);
	fault_205BP  = EIU_EPCU_filter(9,M_fault_205BP, 3, 3);
	fault_258YV  = EIU_EPCU_filter(10,M_fault_258YV, 3, 3);
	fault_257YV  = EIU_EPCU_filter(11,M_fault_257YV, 3, 3);
	fault_267YV  = EIU_EPCU_filter(12,M_fault_267YV, 3, 3);
	fault_253YV  = EIU_EPCU_filter(13,M_fault_253YV, 3, 3);
	fault_254YV  = EIU_EPCU_filter(14,M_fault_254YV, 3, 3);
	fault_96_1YV = EIU_EPCU_filter(15,M_fault_96_1YV, 3, 3);
	fault_96_2YV = EIU_EPCU_filter(16,M_fault_96_2YV, 3, 3);

	BPCM_EM60s_countdown = (BPCM62[5]&0xfc)>>2;
////////////////////////////////////////////////////////////////BPCM-END
////////////////////////////////////////////////////////////////BCCM
	M_fault_201BP =  BCCM72[1]&0x40;
	M_fault_212BP =  BCCM72[1]&0x80;
	M_fault_206BP =  BCCM72[2]&0x01;
	M_fault_269YV =  BCCM72[2]&0x02;
	M_fault_276YV =  BCCM72[2]&0x04;
	M_fault_264YV =  BCCM72[2]&0x08;
	M_fault_198YV =  BCCM72[2]&0x10;
	M_fault_260YV =  BCCM72[2]&0x20;
	M_fault_261YV =  BCCM72[2]&0x40;
	M_fault_207BP =  BCCM72[2]&0x80;

	fault_201BP =  EIU_EPCU_filter(17,M_fault_201BP, 3, 3);
	fault_212BP =  EIU_EPCU_filter(18,M_fault_212BP, 3, 3);
	fault_206BP =  EIU_EPCU_filter(19,M_fault_206BP, 3, 3);
	fault_269YV =  EIU_EPCU_filter(20,M_fault_269YV, 3, 3);
	fault_276YV =  EIU_EPCU_filter(21,M_fault_276YV, 3, 3);
	fault_264YV =  EIU_EPCU_filter(22,M_fault_264YV, 3, 3);
	fault_198YV =  EIU_EPCU_filter(23,M_fault_198YV, 3, 3);
	fault_260YV =  EIU_EPCU_filter(24,M_fault_260YV, 3, 3);
	fault_261YV =  EIU_EPCU_filter(25,M_fault_261YV, 3, 3);
	fault_207BP =  EIU_EPCU_filter(26,M_fault_207BP, 3, 3);

	BCCM_EM60s_countdown = (BCCM72[4]&0xfc)>>2;
////////////////////////////////////////////////////////////////BCCM-END
///////////////////////////////////////////////////////////////IBCM
	M_fault_208BP =  IBCM82[1]&0x20;
	M_fault_213BP =  IBCM82[1]&0x40;
	M_fault_209BP =  IBCM82[1]&0x80;
	M_fault_210BP =  IBCM82[2]&0x01;
	M_fault_265YV =  IBCM82[2]&0x02;
	M_fault_266YV =  IBCM82[2]&0x04;
	M_fault_272YV =  IBCM82[2]&0x08;
	M_fault_196YV =  IBCM82[2]&0x10;

	fault_208BP =  EIU_EPCU_filter(27,M_fault_208BP, 3, 3);
	fault_213BP =  EIU_EPCU_filter(28,M_fault_213BP, 3, 3);
	fault_209BP =  EIU_EPCU_filter(29,M_fault_209BP, 3, 3);
	fault_210BP =  EIU_EPCU_filter(30,M_fault_210BP, 3, 3);
	fault_265YV =  EIU_EPCU_filter(31,M_fault_265YV, 3, 3);
	fault_266YV =  EIU_EPCU_filter(32,M_fault_266YV, 3, 3);
	fault_272YV =  EIU_EPCU_filter(33,M_fault_272YV, 3, 3);
	fault_196YV =  EIU_EPCU_filter(34,M_fault_196YV, 3, 3);
//////////////////////////////////////////////////////////////IBCM-END
	M_BPCM_applyfor_BCCM_Penalty = BPCM63[6]&0x04;
	M_BCCM_BPCMlife_err_Penalty  = BCCM74[6]&0x02;

	BPCM_applyfor_BCCM_Penalty =  EIU_EPCU_filter(37,M_BPCM_applyfor_BCCM_Penalty, 3, 3);
	BCCM_BPCMlife_err_Penalty  =  EIU_EPCU_filter(38,M_BCCM_BPCMlife_err_Penalty, 3, 3);
//////////////////////////////////////////////////////////////
	BPCMsetpointpress  = 400 + BPCM62[6];
	BCCMsetpointpress  = 400 + BCCM72[5];

	if(!BCCM_replace_BPCM)
	{
		BCU_ERPressTarget = (BPCM63[1]<<8) + BPCM63[0];
	}
	else
	{
		BCU_ERPressTarget = (BCCM73[1]<<8) + BCCM73[0];
	}
/////////////////////////////////////////////////////////////
	if(!BPCM_life_err)
	{
		BPsetpoint = BPCMsetpoint;
		BPsetpoint_Press = BPCMsetpointpress;
		EM60s_countdown = BPCM_EM60s_countdown;
	}
	else
	{
		BPsetpoint = BCCMsetpoint;
		BPsetpoint_Press = BCCMsetpointpress;
		EM60s_countdown= BCCM_EM60s_countdown;
	}

	ERPress = (BPCM61[7]<<8) + BPCM61[6];

	if((!BPCM_life_err) && (!fault_204BP))
	{
		BPPress = (BPCM61[5]<<8) + BPCM61[4];
	}
	else if((!BCCM_life_err) && (!fault_212BP))
	{
		BPPress = (BCCM71[5]<<8) + BCCM71[4];
	}

	if((!BPCM_life_err) && (!fault_203BP))
	{
		MRPress = (BPCM61[1]<<8) + BPCM61[0];
	}
	else if((!IBCM_life_err) && (!fault_213BP))
	{
		MRPress = (IBCM81[3]<<8) + IBCM81[2];
	}

	BCPress    = (BCCM71[3]<<8) + BCCM71[2];
	RateofFlow = (BPCM61[3]<<8) + BPCM61[2];

	BPCMfault_to_exitATO = BPCM_applyfor_BCCM||fault_205BP||fault_258YV||fault_257YV||fault_253YV||fault_254YV||fault_96_1YV||fault_96_2YV||fault_267YV;
	BCCMfault_to_exitATO = BCCM_replace_BPCM||(fault_204BP&&fault_212BP);
	IBCMfault_to_exitATO = fault_196YV;

	BCUfault_to_exitATO = BPCMfault_to_exitATO || BCCMfault_to_exitATO || IBCMfault_to_exitATO||EBV_life_err||EBV_autoBrk_Fault;

	if((!fault_200BP) && (RateofFlow>=0) && (RateofFlow<=3000))
		RateofFlow_valid = 1;
	else
		RateofFlow_valid = 0;

	if((!fault_205BP) && (ERPress>=0) && (ERPress<=1000))
		ERPress_valid = 1;
	else
		ERPress_valid = 0;

	if(((!fault_203BP) || (!fault_213BP)) && (MRPress>=0) && (MRPress<=1000))
		MRPress_valid = 1;
	else
		MRPress_valid = 0;

	if(((!fault_204BP) || (!fault_212BP)) && (MRPress>=0) && (MRPress<=1000))
		BPPress_valid = 1;
	else
		BPPress_valid = 0;

	if((BCU_ERPressTarget>=0) && (BCU_ERPressTarget<=650))
	{
		BCU_ERPressTarget_valid = 1;
	}
	else
	{
		BCU_ERPressTarget_valid = 0;
	}
}

void RDP_Function()
{/////MVB发送要取反，MVB接收不用取反
////////////////////////////////////////////发给无线重联MVB
	uint8_t M_BCU_254YV;
	//uint8_t M_BCU_mode;
	uint8_t M_BCU_PenaltyPress_state;
	uint8_t M_BCU_leaktest_state;
	uint8_t M_BCU_RDP_mode;
	static uint8_t RCU_autoBrkHand_EMG_flag;
////////////////////////////////////////////
///////////////////////////////////////////
	switch(BCU_mode)
	{
		case 1://bit0:1  bit1:0,danji
			BCUmode_to_RCU = 0x03;
		break;
		case 2://bit0:0  bit1:1,benji
			BCUmode_to_RCU = 0x02;
		break;
		case 3://bit0:1  bit1:1,buji
			BCUmode_to_RCU = 0x01;
		break;
		case 0://bit0:0  bit1:0,wuxiao
			BCUmode_to_RCU=0x00;
		break;
		default:
			BCUmode_to_RCU=0x00;
	}

	BCU_253YV = (BPCM62[1]&0x02);
	M_BCU_254YV = (BPCM62[1]&0x01);
	BCU_254YV   = EIU_EPCU_filter(35,M_BCU_254YV, 3, 3);

	if(BCU_Penalty || BPCM_applyfor_BCCM_Penalty || BCCM_BPCMlife_err_Penalty)
	{
		if((BCU_ERPressTarget < 100) || BPCM_applyfor_BCCM_Penalty || BCCM_BPCMlife_err_Penalty)
		{
			M_BCU_PenaltyPress_state = 0x02;
		}
		else
		{
			if(BPsetpoint)//500
			{
				if(BCU_ERPressTarget <= BPsetpoint_Press - 135)
					M_BCU_PenaltyPress_state = 0x03;
				else if(BCU_ERPressTarget <= BPsetpoint_Press - 70)
					M_BCU_PenaltyPress_state = 0x01;
				else
					M_BCU_PenaltyPress_state = 0x00;
			}
			else//600
			{
				if(BCU_ERPressTarget <= BPsetpoint_Press - 160)
					M_BCU_PenaltyPress_state = 0x03;
				else if(BCU_ERPressTarget <= BPsetpoint_Press - 70)
					M_BCU_PenaltyPress_state = 0x01;
				else
					M_BCU_PenaltyPress_state = 0x00;
			}
		}
	}
	else
		M_BCU_PenaltyPress_state = 0;

	BCU_PenaltyPress_state = M_BCU_PenaltyPress_state;

	if((RCU_leakPress == 0x03)||(RCU_leakPress == 0x01))
		M_BCU_leaktest_state = 1;
	else
		M_BCU_leaktest_state = 0;

	BCU_leaktest_state = M_BCU_leaktest_state;

	//M_BCU_RDP_mode = RCU_DPmode && RCU_DPmode_valid;
	M_BCU_RDP_mode = RCU_DPmode;//20230522
	BCU_RDP_mode = M_BCU_RDP_mode;

	if(BCU_RDP_mode && (RCU_Loco_mode == 0x01))//congche
	{
		if(RCU_Em_req)
		{
			CAN91RCU_Em_req = 1;
		}
		else //if(EM60s_countdown >=60)
		{
			if(RCU_autoBrkHand_EMG)
			{
				RCU_autoBrkHand_EMG_flag = 1;
			}
			if(RCU_autoBrkHand_EMG_flag)
			{
				if(RCU_ERPressTarget >= BPsetpoint_Press)
				{
					CAN91RCU_Em_req = 0;
					RCU_autoBrkHand_EMG_flag = 0;
				}
			}
		}
		//else
		//{
			//RCU_autoBrkHand_EMG_flag = 0;
		//}
	}
	else
	{
		CAN91RCU_Em_req = RCU_Em_req;
	}
}

void ATO_Function()
{
	uint8_t M_EIULocoSpeedZero;
	static uint8_t IIU_ATO_ena;
	static uint8_t autoBrkHand_RUN_flag;
	static uint8_t Leave_autoBrkHand_RUN;
	static uint8_t ATO_ATOstate_flag;
	static uint16_t M_ATO_ERPressTarget;
	static uint16_t last_ATO_ERPressTarget;
	uint8_t IIU_ATO_exit1 = 0;
	uint8_t IIU_ATO_exit2 = 0;
	uint8_t IIU_ATO_exit3 = 0;

	M_EIULocoSpeedZero = EIU32[2]&0x04;
	EIULocoSpeedZero = EIU_EPCU_filter(36,M_EIULocoSpeedZero,3,3);
	//EIULocoSpeedZero = 0;
	switch(BCU_mode)
	{
		case 1://bit0:1  bit1:0,danji
			BCUmode_to_ATO = 0x02;
		break;
		case 2://bit0:0  bit1:1,benji
			BCUmode_to_ATO = 0x01;
		break;
		case 3://bit0:1  bit1:1,buji
			BCUmode_to_ATO = 0x03;
		break;
		case 0://bit0:0  bit1:0,wuxiao
			BCUmode_to_ATO=0x00;
		break;
		default:
			BCUmode_to_ATO=0x00;
	}

	if(ATO_lifesignal_fault==0)
	{
		if((BCUmode_to_ATO==0x01)&&(BCU_Penalty==0)&&(BCU_Em==0)&&(BCUfault_to_exitATO==0)&&(!(BCU_RDP_mode && (RCU_Loco_mode!=0x02))))
		{//BCU本机，BCU无惩罚，BCU无紧急，BCU无故障，且非从控
			if(EIULocoSpeedZero)
			{
				if((autoBrkHand_MINBRK||autoBrkHand_BRK||autoBrkHand_MAXBRK)&&(indBrkHand_BRK||indBrkHand_MAXBRK)&&(BCPress>80)&&(BPPress<(BPsetpoint_Press-40)))
				{
					IIU_ATO_ena = 1;
				}
				else
					IIU_ATO_ena = 0;
			}
			else//!EIU_Locospeed_zero
			{
				if(autoBrkHand_RUN && indBrkHand_Run)
				{
					IIU_ATO_ena = 1;
				}
				else
					IIU_ATO_ena = 0;
			}
		}
		else
			IIU_ATO_ena = 0;
	}
	else
		IIU_ATO_ena = 0;

	if(!IIU_ATO_state)
	{
		if(IIU_ATO_ena)
		{
			if(ATO_active_req)
			{
				IIU_ATO_state = 1;

				CAN92_ERPressTarget = min(BCU_ERPressTarget,ATO_ERPressTarget);
			}
		}

		Leave_autoBrkHand_RUN = 0;
		IIU_ATO_exit1 = 0;
		IIU_ATO_exit2 = 0;
		IIU_ATO_exit3 = 0;
		ATO_ATOstate_flag = 0;
		Leave_autoBrkHand_RUN = 0;
		autoBrkHand_RUN_flag = 0;
	}
	else//IIU_ATO_state
	{
		if(ATO_ERPressTarget >= (BPsetpoint_Press-20))
		{
			M_ATO_ERPressTarget = ATO_ERPressTarget;
		}
		else
		{
			M_ATO_ERPressTarget = min(CAN92_ERPressTarget,ATO_ERPressTarget);
			M_ATO_ERPressTarget = min(M_ATO_ERPressTarget,BCU_ERPressTarget);
		}

		if(autoBrkHand_RUN)
		{
			autoBrkHand_RUN_flag = 1;
			Leave_autoBrkHand_RUN = 0;
		}
		else if(autoBrkHand_RUN_flag)
		{
			Leave_autoBrkHand_RUN = 1;
		}

		if(ATO_ATOstate)
		{
			ATO_ATOstate_flag = 1;
		}
		else
		{
			if((!ATO_active_req)&&(!ATO_ATOstate_flag))
				IIU_ATO_exit3 = 1;
		}

		if(ATO_lifesignal_fault)
		{
			IIU_ATO_exit1 = 1;
			if(BCU_RDP_mode && (RCU_Loco_mode==0x02))//zhukong
			    CAN92_ERPressTarget = min(BPsetpoint_Press - 80,M_ATO_ERPressTarget);
			else
				CAN92_ERPressTarget = min(BPsetpoint_Press - 100,M_ATO_ERPressTarget);
			CAN92_ERPressTarget = min(CAN92_ERPressTarget,BCU_ERPressTarget);
		}
		else if((BCUmode_to_ATO!=0x01)|| BCUfault_to_exitATO || ATO_exit_req ||((!ATO_ATOstate)&&ATO_ATOstate_flag) || BCU_Penalty || BCU_Em|| Leave_autoBrkHand_RUN)
		{
			IIU_ATO_exit2 = 1;
			ATO_ATOstate_flag = 0;
			CAN92_ERPressTarget = min(BCU_ERPressTarget,M_ATO_ERPressTarget);
		}
		else
		{
			if(autoBrkHand_RUN)
			{
				CAN92_ERPressTarget = M_ATO_ERPressTarget;
			}
			else
			{
				CAN92_ERPressTarget = min(CAN92_ERPressTarget,M_ATO_ERPressTarget);
			}

		}

		if(IIU_ATO_exit1 || IIU_ATO_exit2 || IIU_ATO_exit3)
		{
			IIU_ATO_state = 0;
			IIU_ATO_exit1 = 0;
			IIU_ATO_exit2 = 0;
			IIU_ATO_exit3 = 0;
			ATO_ATOstate_flag = 0;
			Leave_autoBrkHand_RUN = 0;
			autoBrkHand_RUN_flag = 0;
		}

		CAN92_indBrkTarget = ATO_BCPressTarget;
	}

	last_ATO_ERPressTarget = ATO_ERPressTarget;

	BCU_ATO_state = IIU_ATO_state;
}

void UserLoop()
{
	  if(Can1_cnt < 255)
		 Can1_cnt++;
	  else
		 Can1_cnt = 255;

	  if(Can2_cnt < 255)
		 Can2_cnt++;
	  else
		 Can2_cnt = 255;
	////////////////////////////EBV1_CanFlag
	 if(EBV_Can1_cnt < 255)
		 EBV_Can1_cnt++;
	 else
		 EBV_Can1_cnt = 255;

	 if(EBV_Can2_cnt < 255)
		 EBV_Can2_cnt++;
	 else
		 EBV_Can2_cnt = 255;
	///////////////////////////EIU_CanFlag
	 if(EIU_Can1_cnt < 255)
		 EIU_Can1_cnt++;
	 else
		 EIU_Can1_cnt = 255;

	 if(EIU_Can2_cnt < 255)
		 EIU_Can2_cnt++;
	 else
		 EIU_Can2_cnt = 255;
	///////////////////////////BPCM_CanFlag
	 if(BPCM_Can1_cnt < 255)
		 BPCM_Can1_cnt++;
	 else
		 BPCM_Can1_cnt = 255;

	 if(BPCM_Can2_cnt < 255)
		 BPCM_Can2_cnt++;
	 else
		 BPCM_Can2_cnt = 255;
	///////////////////////////BCCM_CanFlag
	 if(BCCM_Can1_cnt < 255)
		 BCCM_Can1_cnt++;
	 else
		 BCCM_Can1_cnt = 255;

	 if(BCCM_Can2_cnt < 255)
		 BCCM_Can2_cnt++;
	 else
		 BCCM_Can2_cnt = 255;
	////////////////////////////IBCM_CanFlag
	 if(IBCM_Can1_cnt < 255)
		 IBCM_Can1_cnt++;
	 else
		 IBCM_Can1_cnt = 255;

	 if(IBCM_Can2_cnt < 255)
		 IBCM_Can2_cnt++;
	 else
		 IBCM_Can2_cnt = 255;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	if(IIU_lifesignal <255)
	{
		IIU_lifesignal++;
	}
	else
	{
		IIU_lifesignal = 128;
	}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	Choose_CANAorB_Data();
	Receive_EBV();
	Receive_MVB();
	Receive_EIU_EPCU();
	RDP_Function();
	ATO_Function();

	BrakeSystype_toRCU = 0xc0;
	BrakeSysID_toATO   = 0x12;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	CAN91[0] = IIU_lifesignal;
	CAN91[1] = RCU_Loco_mode|(RCU_DPmode_valid<<3)|(RCU_DPmode<<4)|(RCU_LocoSpeedZero5km<<6)|(RCU_Comm_fault<<7);
	CAN91[2] = RCU_Penalty_req|(CAN91RCU_Em_req<<1)|(RCU_indBrkHand_REL<<2)|(RCU_leaktest_req3<<3)|(RCU_254YV<<4)|(RCU_leakPress<<6);
	CAN91[3] = RCU_PenaltyPress;
	CAN91[4] = (RCU_ERPressTarget&0x00ff);
	CAN91[5] = (RCU_ERPressTarget&0xff00)>>8;
	CAN91[6] = (RCU_indBrkTarget&0xff00)>>8;
	CAN91[7] = RCU_indBrkTarget&0x00ff;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	CAN92[0] = IIU_lifesignal;
	CAN92[1] = IIU_ATO_state|(ATO_lifesignal_fault<<7);
	CAN92[2] = ATO_indBrkHand_REL;
	CAN92[3] = (MVBATO[3]&0x00ff);//ATO_lifesignal
	CAN92[4] = CAN92_ERPressTarget&0x00ff;
	CAN92[5] = (CAN92_ERPressTarget&0xff00)>>8;
	CAN92[6] = CAN92_indBrkTarget&0x00ff;
	CAN92[7] = (CAN92_indBrkTarget&0xff00)>>8;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////RCU
///MVB发送要取反，MVB接收不用取反

	if(IIU_ATO_state)
	{
		indBrkHand_REL_state = ATO_indBrkHand_REL;
		BCU_indBrkTarget_to_RCUorATO = CAN92_indBrkTarget;

		if((CAN92_indBrkTarget>=0) && (CAN92_indBrkTarget<=300))
			BCU_indBrkTarget_valid = 1;
		else
			BCU_indBrkTarget_valid = 0;
	}
	else
	{
		indBrkHand_REL_state = indBrkHand_REL;
		BCU_indBrkTarget_to_RCUorATO = BCU_indBrkTarget;

		if((!EBV_indBrk_Fault) && (indBrkAI_int>=0) && (indBrkAI_int<=300))
			BCU_indBrkTarget_valid = 1;
		else
			BCU_indBrkTarget_valid = 0;
	}

	MVB137[0]  = (IIU_lifesignal<<8) + (BrakeSystype_toRCU|(BCU_Em<<4)|((BCU_Penalty || BPCM_applyfor_BCCM_Penalty || BCCM_BPCMlife_err_Penalty)<<3)|(BCU_254YV<<2)|BCUmode_to_RCU);
	MVB137[1]  = ((autoBrkHand_EMG<<14)|(autoBrkHand_MUL<<13)|(autoBrkHand_RES<<12)|(autoBrkHand_MAXBRK<<11)|(autoBrkHand_MINBRK<<9)
				 |(autoBrkHand_RUN<<8)|(indBrkHand_REL_state<<3)|(indBrkHand_MAXBRK<<2)|indBrkHand_Run);
	MVB137[2]  = ERPress;
	MVB137[3]  = BPPress;
	MVB137[4]  = MRPress;
	MVB137[5]  = BCPress;
	MVB137[6]  = RateofFlow;
	MVB137[7]  = BCU_ERPressTarget;
	MVB137[8]  = ((BCU_PenaltyPress_state<<14)|(BCU_leaktest_state<<13)|(BCU_RDP_mode<<11)|(BCU_indBrkTarget_valid<<5)|(BCU_ERPressTarget_valid<<4)
				 |(RateofFlow_valid<<3)|(ERPress_valid<<2)|(MRPress_valid<<1)|BPPress_valid);
	MVB137[9]  = BCU_indBrkTarget_to_RCUorATO;
	MVB137[10] = BPsetpoint_Press;
	MVB137[11] = 0;
	MVB137[12] = 0;
	MVB137[13] = 0;
	MVB137[14] = 0;

	CRCBYTE137[1] = MVB137[0]&0x00ff;
	CRCBYTE137[0] = (MVB137[0]&0xff00)>>8;
	CRCBYTE137[3] = MVB137[1]&0x00ff;
	CRCBYTE137[2] = (MVB137[1]&0xff00)>>8;
	CRCBYTE137[5] = MVB137[2]&0x00ff;
	CRCBYTE137[4] = (MVB137[2]&0xff00)>>8;
	CRCBYTE137[7] = MVB137[3]&0x00ff;
	CRCBYTE137[6] = (MVB137[3]&0xff00)>>8;
	CRCBYTE137[9] = MVB137[4]&0x00ff;
	CRCBYTE137[8] = (MVB137[4]&0xff00)>>8;
	CRCBYTE137[11] = MVB137[5]&0x00ff;
	CRCBYTE137[10] = (MVB137[5]&0xff00)>>8;
	CRCBYTE137[13] = MVB137[6]&0x00ff;
	CRCBYTE137[12] = (MVB137[6]&0xff00)>>8;
	CRCBYTE137[15] = MVB137[7]&0x00ff;
	CRCBYTE137[14] = (MVB137[7]&0xff00)>>8;
	CRCBYTE137[17] = MVB137[8]&0x00ff;
	CRCBYTE137[16] = (MVB137[8]&0xff00)>>8;
	CRCBYTE137[19] = MVB137[9]&0x00ff;
	CRCBYTE137[18] = (MVB137[9]&0xff00)>>8;
	CRCBYTE137[21] = MVB137[10]&0x00ff;
	CRCBYTE137[20] = (MVB137[10]&0xff00)>>8;
	CRCBYTE137[23] = MVB137[11]&0x00ff;
	CRCBYTE137[22] = (MVB137[11]&0xff00)>>8;
	CRCBYTE137[25] = MVB137[12]&0x00ff;
	CRCBYTE137[24] = (MVB137[12]&0xff00)>>8;
	CRCBYTE137[27] = MVB137[13]&0x00ff;
	CRCBYTE137[26] = (MVB137[13]&0xff00)>>8;
	CRCBYTE137[29] = MVB137[14]&0x00ff;
	CRCBYTE137[28] = (MVB137[14]&0xff00)>>8;

	MVB137[15] = Comn_F_GetCRC16( c_Crc16Table_aU16,0xffff,CRCBYTE137,30);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////ATO
	MVB702[0]  = 0x6554;
	MVB702[1]  = 0x434e;
	MVB702[2]  = 32;
	MVB702[3]  = ((IIU_lifesignal&0Xff)<<8)|BrakeSysID_toATO;
	MVB702[4]  = 0;
	MVB702[5]  = RateofFlow;
	MVB702[6]  = BPPress;
	MVB702[7]  = BCPress;
	MVB702[8]  = ERPress;
	MVB702[9]  = MRPress;
	MVB702[10] = BPsetpoint_Press;
	MVB702[11] = 0;
	MVB702[12] = 0;
	MVB702[13] = ((BCUmode_to_ATO|((BCU_Penalty || BPCM_applyfor_BCCM_Penalty || BCCM_BPCMlife_err_Penalty)<<2)|(BCU_Em<<3)|(BCUfault_to_exitATO<<4))<<8)|BCU_ATO_state;
	MVB702[14] = ((autoBrkHand_EMG<<14)|(autoBrkHand_MUL<<13)|(autoBrkHand_RES<<12)|(autoBrkHand_MAXBRK<<11)|(autoBrkHand_BRK<<10)|(autoBrkHand_MINBRK<<9)
			     |(autoBrkHand_RUN<<8)|(indBrkHand_REL<<3)|(indBrkHand_MAXBRK<<2)|(indBrkHand_BRK<<1)|indBrkHand_Run);

	CRCBYTE702[1] = MVB702[0]&0x00ff;
	CRCBYTE702[0] = (MVB702[0]&0xff00)>>8;
	CRCBYTE702[3] = MVB702[1]&0x00ff;
	CRCBYTE702[2] = (MVB702[1]&0xff00)>>8;
	CRCBYTE702[5] = MVB702[2]&0x00ff;
	CRCBYTE702[4] = (MVB702[2]&0xff00)>>8;
	CRCBYTE702[7] = MVB702[3]&0x00ff;
	CRCBYTE702[6] = (MVB702[3]&0xff00)>>8;
	CRCBYTE702[9] = MVB702[4]&0x00ff;
	CRCBYTE702[8] = (MVB702[4]&0xff00)>>8;
	CRCBYTE702[11] = MVB702[5]&0x00ff;
	CRCBYTE702[10] = (MVB702[5]&0xff00)>>8;
	CRCBYTE702[13] = MVB702[6]&0x00ff;
	CRCBYTE702[12] = (MVB702[6]&0xff00)>>8;
	CRCBYTE702[15] = MVB702[7]&0x00ff;
	CRCBYTE702[14] = (MVB702[7]&0xff00)>>8;
	CRCBYTE702[17] = MVB702[8]&0x00ff;
	CRCBYTE702[16] = (MVB702[8]&0xff00)>>8;
	CRCBYTE702[19] = MVB702[9]&0x00ff;
	CRCBYTE702[18] = (MVB702[9]&0xff00)>>8;
	CRCBYTE702[21] = MVB702[10]&0x00ff;
	CRCBYTE702[20] = (MVB702[10]&0xff00)>>8;
	CRCBYTE702[23] = MVB702[11]&0x00ff;
	CRCBYTE702[22] = (MVB702[11]&0xff00)>>8;
	CRCBYTE702[25] = MVB702[12]&0x00ff;
	CRCBYTE702[24] = (MVB702[12]&0xff00)>>8;
	CRCBYTE702[27] = MVB702[13]&0x00ff;
	CRCBYTE702[26] = (MVB702[13]&0xff00)>>8;
	CRCBYTE702[29] = MVB702[14]&0x00ff;
	CRCBYTE702[28] = (MVB702[14]&0xff00)>>8;

	MVB702[15] = Comn_F_GetCRC16( c_Crc16Table_aU16,0xffff,CRCBYTE702,30);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////
	MVB706[0]  = MVB702[0];
	MVB706[1]  = MVB702[1];
	MVB706[2]  = MVB702[2];
	MVB706[3]  = MVB702[3];
	MVB706[4]  = MVB702[4];
	MVB706[5]  = MVB702[5];
	MVB706[6]  = MVB702[6];
	MVB706[7]  = MVB702[7];
	MVB706[8]  = MVB702[8];
	MVB706[9]  = MVB702[9];
	MVB706[10] = MVB702[10];
	MVB706[11] = MVB702[11];
	MVB706[12] = MVB702[12];
	MVB706[13] = MVB702[13];
	MVB706[14] = MVB702[14];

	CRCBYTE706[1] = MVB706[0]&0x00ff;
	CRCBYTE706[0] = (MVB706[0]&0xff00)>>8;
	CRCBYTE706[3] = MVB706[1]&0x00ff;
	CRCBYTE706[2] = (MVB706[1]&0xff00)>>8;
	CRCBYTE706[5] = MVB706[2]&0x00ff;
	CRCBYTE706[4] = (MVB706[2]&0xff00)>>8;
	CRCBYTE706[7] = MVB706[3]&0x00ff;
	CRCBYTE706[6] = (MVB706[3]&0xff00)>>8;
	CRCBYTE706[9] = MVB706[4]&0x00ff;
	CRCBYTE706[8] = (MVB706[4]&0xff00)>>8;
	CRCBYTE706[11] = MVB706[5]&0x00ff;
	CRCBYTE706[10] = (MVB706[5]&0xff00)>>8;
	CRCBYTE706[13] = MVB706[6]&0x00ff;
	CRCBYTE706[12] = (MVB706[6]&0xff00)>>8;
	CRCBYTE706[15] = MVB706[7]&0x00ff;
	CRCBYTE706[14] = (MVB706[7]&0xff00)>>8;
	CRCBYTE706[17] = MVB706[8]&0x00ff;
	CRCBYTE706[16] = (MVB706[8]&0xff00)>>8;
	CRCBYTE706[19] = MVB706[9]&0x00ff;
	CRCBYTE706[18] = (MVB706[9]&0xff00)>>8;
	CRCBYTE706[21] = MVB706[10]&0x00ff;
	CRCBYTE706[20] = (MVB706[10]&0xff00)>>8;
	CRCBYTE706[23] = MVB706[11]&0x00ff;
	CRCBYTE706[22] = (MVB706[11]&0xff00)>>8;
	CRCBYTE706[25] = MVB706[12]&0x00ff;
	CRCBYTE706[24] = (MVB706[12]&0xff00)>>8;
	CRCBYTE706[27] = MVB706[13]&0x00ff;
	CRCBYTE706[26] = (MVB706[13]&0xff00)>>8;
	CRCBYTE706[29] = MVB706[14]&0x00ff;
	CRCBYTE706[28] = (MVB706[14]&0xff00)>>8;

	MVB706[15] = Comn_F_GetCRC16( c_Crc16Table_aU16,0xffff,CRCBYTE706,30);
}
